package main

import (
	"fmt"
)

// xiaorui.cc

type Nodes2 struct {
	Order string `json:"order"`
	Attribute  string `json:"attribute"`
	DirName string `json:"dir_name"`
	BookFileId  string `json:"book_file_id"`
	Children []Nodes `json:"children"`
}


func  main()  {
//	m := make(map[string]interface{}, 4)





	var  f1 Nodes
	f1.Order="2"
	f1.Attribute="file"
	f1.BookFileId="45454454545"

	var f2 Nodes
	f2.Order="3"
	f2.Attribute="file"
	f2.BookFileId="45454454545"

	var f3 Nodes
	f3.Order="4"
	f3.Attribute="file"
	f3.BookFileId="45454454545"

	var childrens []Nodes
	childrens= append(append(childrens, f1), f2)

	var father1 Nodes
	father1.Order="1"
	father1.Attribute="folder"
	father1.DirName="第一层文件名称"
	father1.Children=childrens

	fmt.Println("=====================")



	//定义 一个 可以包含任意 数据类型的 切片
	s := make([]interface{}, 0)
	s=append(s,father1)
	s=append(s,f3)

	fmt.Println("=========",s)

	/*
	// map转 json
   result2, err2 := json.Marshal(s)
	if err2 != nil {
		return
	}
	fmt.Println("result2 = ", string(result2))*/

/*
	//json str 转map

	var jsonStr2 string="[{\"attribute\":\"folder\",\"children\":[{\"attribute\":\"file\",\"book_file_id\":\"45454454545\",\"children\":null,\"dir_name\":\"\",\"order\":\"2\"},{\"attribute\":\"file\",\"book_file_id\":\"45454454545\",\"children\":null,\"dir_name\":\"\",\"order\":\"3\"}],\"dir_name\":\"第一层文件名称\",\"order\":\"1\"},{\"order\":\"4\",\"attribute\":\"file\",\"dir_name\":\"\",\"book_file_id\":\"45454454545\",\"children\":null}]"
	//var dat map[string]interface{}
	if err := json.Unmarshal([]byte(jsonStr2), &s); err == nil {
		fmt.Println("==============复杂json 转map=======================")
		fmt.Println(s)
		//切片的长度 和容量
		fmt.Println("切片的长度 和容量")
		fmt.Println(len(s),cap(s)) //3 10 容量一般到 末尾
	}





	// 字符串分割，返回切片
	str := "foo@bar@hhh"
	fmt.Println(strings.Split(str, "@"))

	var  strSplits []string=strings.Split(str, "@")
	//切片的长度 和容量
	fmt.Println("切片的长度 和容量")
	fmt.Println(len(strSplits),cap(strSplits)) //3 10 容量一般到 末尾*/
}





/*func main() {
	body := `
  {
      "url": "http://xiaorui.cc",
      "title": "golang and python",
      "admin": "fengyun",
      "email": "rfyiamcool@163.com",
      "address": [
          "beijing",
          "qingdao"
      ],
      "article": [
          {
              "date": "2014",
              "content": "golang json push to redis server",
              "brief": "golang json",
              "keyword": "json",
              "version": {
                  "max": 3,
                  "last": "2016-03-11",
                  "detail": [
                      {
                          "time": "2016-03-12",
                          "ops": "add my email"
                      }
                     ]
                  }
          }
      ]
  }
  `

	var r Response
	err := json.Unmarshal([]byte(body), &r)
	if err != nil {
		fmt.Printf("err was %v", err)
	}

	fmt.Println(r.Article[0].Version.Max)
	fmt.Println(r.Article[0].Version.Detail[0].Ops)

}
*/